<template>
  <div>
    <ul>
      <li :style="{ opacity }">欢迎学习Rust</li>
      <li>news001<input type="text"></input></li>
      <li>news002<input type="text"></input></li>
      <li>news003<input type="text"></input></li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'News',
  data() {
    return {
      opacity: 1
    }
  },
  // mounted() {
  //   console.log('mounted', this)
  //   this.timer = setInterval(() => {
  //     this.opacity -= 0.01;
  //     if (this.opacity <= 0) this.opacity = 1
  //   }, 16);
  // },
  // beforeDestroy() {
  //   console.log('news即将被销毁了');
  //   clearInterval(this.timer)
  // },
  activated() {
    console.log('activated')
    this.timer = setInterval(() => {
      this.opacity -= 0.01;
      if (this.opacity <= 0) this.opacity = 1
    }, 16);
  },
  deactivated() {
    console.log('deactivated')
    clearInterval(this.timer)
  },
}
</script>

<style lang="scss" scoped></style>